﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Xml.Ogc.Ows;
using System.Threading;
using Core.Log;
using System.Xml.Linq;
using Core.Xml;

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            AutoResetEvent resetEvent = new AutoResetEvent(false);

            // Log writer thread.
            Thread t = new Thread(new ThreadStart(delegate()
            {
                // Get logger instance
                Logger logger = Logger.GetInstance();
                // while resetEvent is not signaled
                while (!resetEvent.WaitOne(100))
                {
                    // until logger has no elements
                    while (logger.HasElements)
                    {
                        ILog log = logger.Dequeue();
                        Console.WriteLine(Enum.GetName(typeof(LogPriority), log.Priority) + " : " + log.Message);
                    }
                }
            }));
            t.Start();

            LanguageStringType ls = new LanguageStringType() { Value = "Hello world!", Language = "t" };
            while (true)
            {
                ls.Language = Console.ReadLine();
                if (ls.Language == "")
                    break;
            }
            Console.WriteLine(ls.CreateXElement("content"));

            // This is the GetCapabilities response for testing, in the end it will be wrapped in a class.
            #region GetCapabilities
            XElement capabilities = new XElement(Namespaces.WPS + "Capabilities",
                    new XAttribute(XNamespace.Xmlns + "wps", Namespaces.WPS.NamespaceName),
                    new XAttribute(XNamespace.Xmlns + "xsi", Namespaces.XSI.NamespaceName),
                    new XAttribute(XNamespace.Xmlns + "ows", Namespaces.OWS.NamespaceName),
                    new XAttribute(XNamespace.Xmlns + "xlink", Namespaces.XLINK.NamespaceName),
                    new XAttribute(XNamespace.Xml + "lang", "tr-TR"),
                    new XAttribute(Namespaces.XSI+ "schemaLocation", "http://www.opengis.net/wps/1.0.0 ../wpsGetCapabilities_response.xsd"),
                    new XAttribute("updateSequence", "1"),
                    new XAttribute("service", "WPS"),
                    new XAttribute("version", "1.0.0")
            );
            capabilities.Add(new ServiceIdentification().CreateXElement());



            Console.Clear();
            Console.WriteLine(capabilities);
            #endregion 

            Console.ReadLine();
            // Exiting the program, signal the reset event so that the Log thread should finish.
            resetEvent.Set();
        }
    }
}
